package com.whw.fy.service.impl;

import com.whw.fy.entity.Message;
import com.whw.fy.mapper.StaffMapper;
import com.whw.fy.mapper.StudentMapper;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import com.whw.fy.entity.Excute;
import com.whw.fy.mapper.ExcuteMapper;
import com.whw.fy.service.ExcuteService;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;

@Service
public class ExcuteServiceImpl implements ExcuteService {

    @Resource
    private ExcuteMapper excuteMapper;
    @Resource
    private StaffMapper staffMapper;
    @Resource
    private StudentMapper studentMapper;

    @Override
    public Message deleteByPrimaryKey(Integer excuteId) {
        return excuteMapper.deleteByPrimaryKey(excuteId) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message insert(Excute excute) {
        return excuteMapper.insert(excute) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message insertSelective(Excute excute) {
        return excuteMapper.insertSelective(excute) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message selectByPrimaryKey(Integer excuteId) {
        return Message.success(null).add(excuteMapper.selectByPrimaryKey(excuteId));
    }

    @Override
    public Message updateByPrimaryKeySelective(Excute excute) throws ParseException {
        if (excute.getExcuteStarttimeToString() != null) {
            SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            excute.setExcuteStarttime(simpleDateFormat.parse(excute.getExcuteStarttimeToString()));
        }
        return excuteMapper.updateByPrimaryKeySelective(excute) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message updateByPrimaryKey(Excute excute) {
        return excuteMapper.updateByPrimaryKey(excute) > 0 ? Message.success(null) : Message.fail(null);
    }

    @Override
    public Message selectAll() {
        return Message.success(null).add(excuteMapper.selectAll());
    }


}
